Repository navigation
feat(server): sweep the objects that no row names - #526
Conversation
Review findings that stay openThe review gate (one review and one re-review) found these. Each fixed finding is in the commits. Each open finding has its reason here. Fixed
Open
|
|
Maintainer decision on M2: keep the documented rule (each database gets its own bucket, as backend.md, attachments.md, and template-updates.md state). No code fence in this PR. |
#527) ## Why A hung Server or a dropped network kept the SPA pending with no end. An upload had no cancel. Now each request has a time limit at the BFF and in the SPA, and the user can cancel an upload. ## What changed - The BFF forwarder has a 30 s idle limit, and a multipart upload has 5 min (`Bff:Proxy` options, one row per content type). A request that reaches its limit gets a 504. - The SPA API client stops a request after 35 s, or 10 min for an upload. A 504 or a timeout shows one message: "The server did not answer in time. Reload the page to see the latest data, then try again." - During an upload, the Files section shows a "Cancel upload" button. It stops the request, goes back to idle, moves the focus to the upload button, and shows no toast. ## Scope - Covers every proxied API call and the attachment upload. - Does not add retries or a dedupe of uploads. ## Tradeoffs - No dedupe. If the Server already saved a file when the user cancels, the file stays, and a second upload adds a copy. The Limits section of the attachments doc says so. A dedupe key costs more than a rare duplicate that the user can delete. - The upload limit is a BFF option and not the Server's `Attachments:AddTimeout`, because main has no such setting. When #526 lands, set the BFF value from it. - The SPA limits count the total time, so they are a little longer than the BFF idle limits. The 504 of the BFF comes first, and the SPA limit stops the wait only when the BFF itself does not answer. ## Blast Radius The change touches all proxied API calls. A Server call that sends no bytes for 30 s now fails with a 504. The Server has no streaming or long-poll endpoint today. ## Verification - Before the fix, the new BFF, Playwright claim, and cancel tests failed. After it, they pass, and each new Playwright test passed 10 of 10 runs with `--repeat-each=10`. - The tests of a hung request set a short limit, so they do not wait for the real ones. The BFF test sets `Bff:Proxy:ActivityTimeout` to 1 s (30 s before, now 1.8 s). The Playwright claim test cuts the browser limit of the claim request to 1 s with `shortenRequestTimeLimit` (36.1 s before, now 1.5 to 2.5 s). The browser counts the XHR limit, so `page.clock` cannot reach it. A BFF test and the SPA unit test pin the defaults: 30 s, 5 min, 35 s, and 10 min. With the limit code removed, each shortened test fails. - The solution builds with 0 warnings. 516 BFF tests pass, and `pnpm lint`, `pnpm build`, `pnpm test` (874 tests), `join.spec.ts` with `--repeat-each=10` (540 of 540), and `pnpm test:e2e` (360 tests) pass. - On the live stack, a throttled real upload stopped when the user pressed Cancel upload, with no toast. Light, dark, and narrow screenshots look correct.
…deletes The model comes from fv/object-storage and now describes the code at 80d9f8f. The jobs of the object-deletes queue replace the request runner: an outcome is fenced on the lease, and an expired lease counts as an attempt. The put is inside the try, and a canceled save runs the cleanup. F1 (an object with no row that no code deletes) and F2 (a late COMMIT whose object the cleanup deletes) still show.
The model adds a recurring sweep: it lists the bucket, keeps the keys older than the grace, reads the live rows, and deletes the rest. OrphansGo proves under fairness of the sweep that each object with no live row goes, also the object that lands under a deleted tenant after its prefix delete. The configs show the decisions of the code that follows. The grace needs the time limit of an add and a margin for a COMMIT in flight (GraceNone, GraceLimit). A soft-deleted row must not keep its object (SoftDeletedNames). The cleanup at once of a failed add is the cause of F2 (LateCommit), and with it gone the safety gate passes with late commits on.
The sweep of the bucket looks up each page of keys in each attachment table. EF Core 10 cannot index a column of a value object, so the migration adds the index. AttachmentStorageKeyIndexTests fails on an attachment table with no index on storage_key.
The put and the save of an add had no time limit of their own. An add whose caller waited on could run for any time, so no age of an object in the bucket proved that its add had ended. The add now stops its put and its save after Attachments:AddTimeout (5 minutes) and throws a TimeoutException. The save of the row gets the token of the limit, and gives it to the tenant lock.
An add that stops between its put and its save leaves an object with no row, and so does a put that lands after the delete of the objects of its tenant. No code deleted these objects. SweepObjects is a recurring system job on the queue object-sweep. It runs each day at 03:00 UTC, lists the bucket under tenants/ one page at a time, and deletes each object that is older than AddTimeout plus a margin, whose tenant is a tenant of the database, and that no live row names in a StoredFile column. StoredFileMapping.StorageKeyColumns finds these columns in the EF model, also on a derived entity type and inside another value object, and refuses a stored file that it cannot read. A soft-deleted row does not name its key. StorageKeyIndexTests, the old AttachmentStorageKeyIndexTests, checks the index of each such column. The sweep does not run while the database has a migration that the Server does not know, so an older Server does not delete the objects of a newer storage key column. ObjectSweep holds the decision as a pure function, and the handler only reads and deletes. The S3 client no longer corrects its clock to the clock of S3. S3 then refuses each call of a Server whose clock is more than 15 minutes off, and the grace of the sweep needs that bound.
A save can throw while its COMMIT is still in flight. The cleanup of the failed add then checked for the row on a new connection, saw none, and deleted the object, and the COMMIT landed: the list showed a file that no one could download (F2 in the object storage model). The add now keeps the object when the put or the save throws. The sweep of the bucket deletes it after the grace, when a COMMIT in flight has landed or failed. The test of a lost put reply now shows that the object stays after the add and that the sweep deletes it.
The coverage record now maps Age, SweepList, SweepCheck, SweepDelete, and SweepFail to SweepObjects, ObjectSweep, NamedStorageKeys, and ObjectSweepSchedule. The sync commit moves to 83bdc7ae, where the model with Cleanup = FALSE describes the code. check.sh stays at its baseline.
… model The model is core, so an app with no examples keeps it. CheckWorkshop is now CheckOwner, the comments name the add and delete handler of an attachment, and the lines of SKILL.md that name the workshop handlers or their tests are in example sections. The model semantics are the same.
ff2ed66 to
157c4ea
Compare
…sh commits on main (#533) ## Why The formal verification skills must stay true to the code on main. The three TLA+ skills recorded sync commits from their PR branches. A squash merge left those commits off main, so the `git log <sync>..HEAD` check in each skill named a commit that main does not have. ## What changed - `bff-session-lifecycle` now syncs to `a1637f8a` (#525). `object-storage-lifecycle` syncs to `d4c3fef7` (#526). `membership-lifecycle` syncs to `adeb4db0` (#528). - The skills cited other branch commits as history. Each of those now names the main commit that holds the same code, which is #519 or #521. ## Scope - No change to a model, a config, or `check.sh`. The covered code that main changed after each branch point does not change what the models describe. - No product code changes. ## Blast Radius Only skill text changes, so the app is not affected. An agent that uses these skills now compares against commits that exist on main. ## Verification - `bff-session-lifecycle/model/check.sh` printed only `ok` lines. `object-storage-lifecycle/check.sh` kept every config at its baseline. `membership-lifecycle/check.sh` passed all 4 configs. - `scripts/remove-examples.cs` and the example-name grep of `without-examples.cs` passed on a copy of this branch. The full script stopped at its Docker check because Docker Desktop did not start.
Why
Each non-terminal state of an attachment needs a sure way out, also after a crash. Two faults had none:
DeleteTenantObjectsjob listed the prefix.What changed
SweepObjectsis a recurring BackWave system job on its own queueobject-sweep, inDomain/ObjectDeletes/. Each run lists the objects undertenants/, one page of 1000 keys at a time. It deletes an object only when all of these are true:Attachments:AddTimeout(5 min) plusObjectStorage:Sweep:Margin(1 h).StoredFilecolumn.ObjectSweep.VerdictOfandObjectSweep.Decidemake the decision, with unit tests. The handler only lists, queries, and deletes.StoredFileMapping.StorageKeyColumnsfinds eachStoredFilecolumn there, also on a derived entity type and inside another value object, so a new stored file needs no change to the sweep. A collection of stored files, or a stored file in one column, stops the sweep, because it cannot read their keys. A soft-deleted row does not name its key.Attachments:AddTimeoutstops the put and the save, also when the caller does not cancel. So the grace is a real bound. A migration indexesstorage_key, andStorageKeyIndexTestsfails for a storage key column with no such index.AttachmentStorage.AddAsynckeeps the object when the put or the save throws. The sweep deletes it after the grace, when a COMMIT in flight has landed or failed. This removes the cleanup that fix(server): delete the object of an attachment whose put throws in AttachmentStorage.AddAsync #519 extended.ObjectStorageRegistrationturns off the clock skew correction of the SDK. With it on, the SDK signs with the clock of S3 after one refusal, so the 15-minute rule of S3 did not bound the clock that the sweep reads. Now S3 refuses each call of a Server whose clock is more than 15 minutes off.ObjectStorageClockTestschecks this against a fake S3 whose clock is 20 minutes ahead.ISystemJobandSystemJobHandlerrun a job as the callerSystem.JobScopegives it the same telemetry and unsaved-work check as a tenant job.object-storage-lifecycle(TLA+) models the sweep. Its coverage record maps each sweep action to its code, at the sync commitc5abb78b.Scope
ObjectStorage:Sweep:Schedule, cron). The schedule uses Coalesce, so missed ticks give one run, and noOverlap is on. Each start of the Server defines the schedule after the migrations.tenants/. That is one LIST request for each 1000 objects. Each page also runs one query ontenantsand one indexed query on each storage key column, plus one DeleteObjects call when the page has orphans. At 1 million objects, a run is about 1000 LIST requests.Tradeoffs
AddTimeoutstops each add.Marginmust be over 15 min, and the start fails otherwise.GraceLimit.cfgshows the harm.backend.md,attachments.md, andtemplate-updates.md.scripts/remove-examples.cs, skips each sweep until a person deletes that history row. The Warning log names each such migration.docs/examples.mdand the script tell how.Blast Radius
tenants/must be theStoredFileof a row. An app that keeps other files undertenants/loses them on the first run after the grace.template-updates.mdsays to move such files first.template-updates.mdsays to keep each host on NTP.s3:ListBucket. The credentials of each process that runs jobs need it. They already need it for a tenant delete.Kept the object of attachment,Could not delete the object of unsaved attachment, andThe save of attachment ... failed after its commit.object-sweep, with a default worker group. The schedule row issweep-objectsin thebackwaveschema. The jobs dashboard still refuses a manual trigger of a schedule.AttachmentStorage.AddAsyncgives the save a token. Each app attachment add must passaddTokentoRunSharedAsync, and the build fails until it does (template-updates.md).Verification
dotnet build FullstackTemplate.slnxgives 0 warnings and 0 errors.ServerRoleTests6/6,JobsDashboardTests7/7, andWorkshopAttachmentTests16/16 pass.backwave.scheduleshassweep-objectswith0 0 3 * * *, a catch-up of 1, and no overlap. A sweep that I enqueued through CSharpRepl loggedSwept the bucket: listed 2 objects, kept 2, and deleted 0. Its span hasapp.caller.kind=systemand the three count tags, and its query ontenantshas no soft-delete filter.SweepObjectsTestsand bothWorkshopAttachmentSweepTestsfail.<=changed to<at the grace: the boundary unit test fails.IAttachmenttypes,Fileonly): bothStorageKeyColumnsTestsof the scan fail.ObjectStorageClockTestsfails, because the SDK takes the clock of the fake S3 and the list works.check.shhas all 8 configs at baseline.ObjectStorage,Liveness, andChartpassed. Configs with orphans brokeEveryObjectAccountedandNoObjectLeftInDeletedTenant.LateCommitbrokeNoLiveRowWithoutObject(F2).ObjectStorage(904,176 states),Liveness, andChartpass with late commits on.DeletedTenantOrphanshows thatOrphansGoholds.GraceNone,GraceLimit, andSoftDeletedNamesshow the harm of each other choice.